<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of UserRegister
 *
 * @author Animus Inc.
 */

// Restrict Unrestricted Access

defined("_dispatch") or	die("Access Denied !");

// Constants

define('DOMROOT', dirname(dirname(__FILE__)));

// Imports

require_once DOMROOT.'/classes/abstract/Component.php';
require_once DOMROOT.'/views/UserRegistrationView.php';
require_once DOMROOT.'/forms/UserRegistrationForm.php';
require_once DOMROOT.'/models/UserRegistrationModel.php';


class UserRegister extends Component{
    //put your code here
    
    private $view;
    private $model;
    private $bootstrap;
    
    public function __construct() {
        
        $this->init();
        $this->service();
        $this->destroy();
        
        return;
    }
    public function init() {
        
        $this->view = new UserRegistrationView();
        $this->model= new UserRegistrationModel();
        
        return;
        
    }
    public function service() {
        $form = new UserRegistrationForm();
        $method = $form->getMethod();
        $attributes = array();
        $flag = false;
        
        switch($method){

         case("post"||"POST"): $submit_flag = $form -> handleSubmit($_POST);
          break;
         case("get"||"GET"): $submit_flag = $form -> handleSubmit($_GET);
          break;
        }
		
    if($submit_flag) $flag = $form -> validate();
    if(!$flag)
        {
            $this->view->setForm($form);
            $this->view->output();
        }
    else {
            $attributes = $form->getAttributes();
            $this->model->setAttributes($attributes);
            $this->model->save();
        }
	
        return;
    }
    public function destroy() {
        $this->view = null;
        $this->model = null;
        
        return;
    }
    
    public  function setBootstrap($message){
        
        $this ->bootstrap = $message;

    }
}

?>
